﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FriendStar.Code;
using FriendStar.Domain.Entity.MainData;
using FriendStar.Application.MainData;
using FriendStar.Domain.Entity.BOM;
using FriendStar.Application.BOM;
using FriendStar.Domain.Entity.SystemManage;
using FriendStar.Application.SystemManage;
using FriendStar.Repository.Infrastructure;

namespace FriendStar.Web.Areas.BOM.Controllers
{
    public class ManufactureController : ControllerBase
    {
        //
        // GET: /BOM/Manufacture/
        private string UseUnit = Configs.GetValue("UseUnit");
        private string FactoryFlag = Configs.GetValue("FactoryFlag"); 

        V_LXK_13_LX_ProductListInApp v_lxk_13_lx_productlistinApp = new V_LXK_13_LX_ProductListInApp();
        V_LXK_14_LX_ProductListIn_DAApp v_lxk_14_lx_productlistin_daApp = new V_LXK_14_LX_ProductListIn_DAApp();
        V_GYK_61_WL_DatStorTransApp v_gyk_61_wl_datstortransApp = new V_GYK_61_WL_DatStorTransApp();
        V_GYK_62_WL_DatStorTrans_DAApp v_gyk_62_wl_datstortrans_daApp = new V_GYK_62_WL_DatStorTrans_DAApp();       
        GYK_61_WL_DatStorTransApp gyk_61_wl_datstortransApp = new GYK_61_WL_DatStorTransApp();
        GYK_62_WL_DatStorTrans_DAApp gyk_62_wl_datstortrans_daApp = new GYK_62_WL_DatStorTrans_DAApp();
        V_BUS_SJ_DictionaryApp v_bus_sj_dictionaryApp = new V_BUS_SJ_DictionaryApp();
        LXK_13_LX_ProductListInApp lxk_13_lx_productlistinApp = new LXK_13_LX_ProductListInApp();
        LXK_14_LX_ProductListIn_DAApp lxk_14_lx_productlistin_daApp = new LXK_14_LX_ProductListIn_DAApp();
        LXK_16_LX_MakeLineApp lxk_16_lx_makelineApp = new LXK_16_LX_MakeLineApp();
        ZSJ_21_RQ_DatContainerApp zsj_21_rq_datcontainerApp = new ZSJ_21_RQ_DatContainerApp();
        ZSJ_22_TP_PalletApp zsj_22_tp_palletApp = new ZSJ_22_TP_PalletApp();
        ZSJ_B1_GH_SupplierInformationApp zsj_b1_gh_supplierinformationApp = new ZSJ_B1_GH_SupplierInformationApp();
        CLDE_ZD_FL_CLDEerialClassNOApp clde_zd_fl_cldeerialclassnoApp = new CLDE_ZD_FL_CLDEerialClassNOApp();
        CLDE_11_MX_CLDEerialQuotaApp clde_11_mx_cldeerialquotaApp = new CLDE_11_MX_CLDEerialQuotaApp();
        V_CLDE_11_MX_CLDEerialQuotaApp v_clde_11_mx_cldeerialquotaApp = new V_CLDE_11_MX_CLDEerialQuotaApp();
        CLDE_12_GG_CLDEerialQuota_DAApp clde_12_gg_cldeerialquota_daApp = new CLDE_12_GG_CLDEerialQuota_DAApp();
        CLDE_31_TC_CLDEerialCombineApp clde_31_tc_cldeerialcombineApp = new CLDE_31_TC_CLDEerialCombineApp();
        V_CLDE_31_TC_CLDEerialCombineApp v_clde_31_tc_cldeerialcombineApp = new V_CLDE_31_TC_CLDEerialCombineApp();
        ZSJ_11_LJ_ProductionApp zsj_11_lj_productionApp = new ZSJ_11_LJ_ProductionApp();
        Equ_11_DA_CEquipInfoApp equ_11_da_cequipinfoApp = new Equ_11_DA_CEquipInfoApp();
        GYK_51_JQ_TecGXDataApp gyk_51_jq_tecgxdataApp = new GYK_51_JQ_TecGXDataApp();
        GYK_52_JQ_ProductTimeApp gyk_52_jq_producttimeApp = new GYK_52_JQ_ProductTimeApp();
        LXK_11_ML_ProductListApp lxk_11_ml_productlistApp = new LXK_11_ML_ProductListApp();
        V_ZSJ_11_LJ_ProductionApp v_zsj_11_lj_productionApp = new V_ZSJ_11_LJ_ProductionApp();
        V_Mol_11_DA_MoldApp v_mol_11_da_moldApp = new V_Mol_11_DA_MoldApp();
        GYK_42_CY_ProductTimeApp gyk_42_cy_producttimeApp = new GYK_42_CY_ProductTimeApp();
        GYK_41_CY_TecGXDataApp gyk_41_cy_tecgxdataApp = new GYK_41_CY_TecGXDataApp();
        V_LXK_11_ML_ProductListApp v_lxk_11_ml_productlistApp = new V_LXK_11_ML_ProductListApp();
        Sys_RunParamApp sys_runparamApp = new Sys_RunParamApp();
        PLM_CP_VEHICLENUMBERApp plm_cp_vehiclenumberApp = new PLM_CP_VEHICLENUMBERApp();
        V_GYK_51_JQ_TecGXDataApp v_gyk_51_jq_tecgxdataApp = new V_GYK_51_JQ_TecGXDataApp();
        V_GYK_53_JQ_TecGXData_DAApp v_gyk_53_jq_tecgxdata_daApp = new V_GYK_53_JQ_TecGXData_DAApp();
        V_GYK_41_CY_TecGXDataApp v_gyk_41_cy_tecgxdataApp = new V_GYK_41_CY_TecGXDataApp();
        V_GYK_43_CY_TecGXData_DAApp v_gyk_43_cy_tecgxdata_daApp = new V_GYK_43_CY_TecGXData_DAApp();
        GYK_43_CY_TecGXData_DAApp gyk_43_cy_tecgxdata_daApp = new GYK_43_CY_TecGXData_DAApp();
        GYK_53_JQ_TecGXData_DAApp gyk_53_jq_tecgxdata_daApp = new GYK_53_JQ_TecGXData_DAApp();
        V_CLDE_41_YL_BLCornerApp v_clde_41_yl_blcornerApp = new V_CLDE_41_YL_BLCornerApp();
        CLDE_41_YL_BLCornerApp clde_41_yl_blcornerApp = new CLDE_41_YL_BLCornerApp();

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ProcessRouteIndex()
        {
            return View();
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ProcessRouteList(string status)
        {
            status = string.IsNullOrEmpty(status) ? "0" : status;
            ViewBag.status = status;
            ViewBag.assembleLine = lxk_16_lx_makelineApp.GetList(new Pagination() { rows = 10000000, sidx = "MakeLineNO", sord = "ASC" }, "");
            ViewBag.productType = v_bus_sj_dictionaryApp.GetListByClassNo("04");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGylxDetailJson(Pagination pagination, string GGDH, string FProduction, string ProductType, string AssembleLine)
        {
            var data = new
            {
                rows = v_lxk_13_lx_productlistinApp.GetList(pagination, GGDH: GGDH, FProduction:FProduction, ProductType:ProductType, AssembleLine:AssembleLine),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGylxDocumentJson(Pagination pagination, string GGDH, string FProduction, string ProductType, string AssembleLine)
        {
            var data = new
            {
                rows = v_lxk_14_lx_productlistin_daApp.GetList(pagination, GGDH, FProduction, ProductType, AssembleLine),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ProcessRouteInput(string status, string number)
        {
            ViewBag.status = (status != "U" && status != "D") ? "I" : status;
            ViewBag.number = (number == null) ? "" : number;
            ViewBag.productType = v_bus_sj_dictionaryApp.GetListByClassNo("04");
            ViewBag.routeType = v_bus_sj_dictionaryApp.GetListByClassNo("05");
            ViewBag.rankNO = v_bus_sj_dictionaryApp.GetListByClassNo("06");
            ViewBag.qualityDemand = v_bus_sj_dictionaryApp.GetListByClassNo("07");
            ViewBag.ggdh = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "路线更改单", OperatorProvider.Provider.GetCurrent().UserCode, "", "正式");
            if (status == "U" || status == "D")
            {
                ViewBag.oldEntity = v_lxk_13_lx_productlistinApp.GetItem(number).ToJson();
            }
            return View();
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ChooseMakeLine(string status, string result)
        {
            status = string.IsNullOrEmpty(status) ? "0" : status;
            ViewBag.status = status;
            ViewBag.result = result;
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetMakeLineJson(Pagination pagination, string keyword)
        {
            var data = new
            {
                rows = lxk_16_lx_makelineApp.GetList(pagination, keyword),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpPost]
        [HandlerAjaxOnly]
        //[ValidateAntiForgeryToken]
        public ActionResult SubmitProcessRouteForm(string status, LXK_13_LX_ProductListInEntity entity, LXK_14_LX_ProductListIn_DAEntity daEntity, string ProductionSumDetail, string keyValue)
        {
            if (string.IsNullOrEmpty(entity.StartDate))
            {
                entity.StartDate = DateTime.Now.ToString("yyyy-MM-dd");
            }
            if (string.IsNullOrEmpty(entity.StopDate))
            {
                entity.StartDate = "9999-12-31";
            }
            if (status == "I")
            {
                LXK_13_LX_ProductListInEntity oldEntity = lxk_13_lx_productlistinApp.GetItem(entity.FProductionNO, entity.AssembleLine);
                if (oldEntity != null)
                {
                    LXK_14_LX_ProductListIn_DAEntity oldDaEntity = new LXK_14_LX_ProductListIn_DAEntity();
                    EntityClone.Clone<LXK_13_LX_ProductListInEntity, LXK_14_LX_ProductListIn_DAEntity>(oldEntity, oldDaEntity);
                    oldDaEntity.GGDH = daEntity.GGDH;
                    oldDaEntity.ChangeType = "Q";
                    lxk_14_lx_productlistin_daApp.SubmitForm(oldDaEntity, "");

                    oldEntity.StopDate = entity.StopDate.ToDate().AddDays(-1).ToString("yyyy-MM-dd");
                    lxk_13_lx_productlistinApp.SubmitForm(oldEntity, oldEntity.ProductionID);
                }

                lxk_13_lx_productlistinApp.SubmitForm(entity, "");

                daEntity.ChangeType = "C";
                lxk_14_lx_productlistin_daApp.SubmitForm(daEntity, "");


                List<SimpleClass> valueList = ProductionSumDetail.ToList<SimpleClass>();
                lxk_13_lx_productlistinApp.SetProductSum(entity.FProductionNO, valueList);

                return Success("输入操作成功。");
            }
            else if (status == "D")
            {
                LXK_13_LX_ProductListInEntity oldEntity = lxk_13_lx_productlistinApp.GetForm(keyValue);

                LXK_14_LX_ProductListIn_DAEntity oldDaEntity = new LXK_14_LX_ProductListIn_DAEntity();

                EntityClone.Clone<LXK_13_LX_ProductListInEntity, LXK_14_LX_ProductListIn_DAEntity>(oldEntity, oldDaEntity);
                oldDaEntity.GGDH = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "路线更改单", OperatorProvider.Provider.GetCurrent().UserCode, "", "正式");
                oldDaEntity.ChangeType = "Q";

                lxk_13_lx_productlistinApp.DeleteForm(oldEntity.ProductionID);

                lxk_14_lx_productlistin_daApp.SubmitForm(oldDaEntity, "");

                return Success("删除操作成功。");
            }
            else
            {
                return Error("不可识别的操作类型。");
            }
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ProductionSumManage(string number, string name)
        {
            ViewBag.number = number;
            ViewBag.name = name;
            var list = v_lxk_11_ml_productlistApp.GetProductionSumList(number);
            List<V_LXK_11_ML_ProductListGroupEntity> groupList = new List<V_LXK_11_ML_ProductListGroupEntity>();
            V_LXK_11_ML_ProductListGroupEntity group = new V_LXK_11_ML_ProductListGroupEntity();
            for (int i = 0; i < list.Count; i++)
            {
                if ((i % 40) == 0)
                {
                    int begin = i + 1;
                    int end = (i + 40) > list.Count ? list.Count : (i + 40);
                    group = new V_LXK_11_ML_ProductListGroupEntity();
                    group.title = string.Format("{0}--{1}", begin, end);
                    group.list = new List<V_LXK_11_ML_ProductListEntity>();
                    groupList.Add(group);
                }
                group.list.Add(list[i]);
            }
            ViewBag.groupList = groupList;
            return View();
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitProductionSumManage(string FProductionNO, string values)
        {
            List<SimpleClass> valueList = values.ToList<SimpleClass>();
            int result = lxk_13_lx_productlistinApp.SetProductSum(FProductionNO, valueList);
            if (result > 0)
            {
                return Success("保存成功。");
            }
            else
            {
                return Error("保存失败。");                
            }
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ProcessRouteCate()
        {
            ViewBag.productClass = v_bus_sj_dictionaryApp.GetListByClassNo("07");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetProcessRouteCateJson(Pagination pagination, string FProductNO, string FProductName, string FProductClass, string MaintainStatus)
        {
            var data = new
            {
                rows = v_lxk_11_ml_productlistApp.GetList(pagination, FProductNO, FProductName, FProductClass, MaintainStatus),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ProcessRouteCateInput(string status, string number)
        {
            ViewBag.currUser = OperatorProvider.Provider.GetCurrent().UserName;
            ViewBag.status = (status != "U" && status != "D") ? "I" : status;
            ViewBag.number = (number == null) ? "" : number;
            ViewBag.productClass = v_bus_sj_dictionaryApp.GetListByClassNo("07");
            if (status == "U")
            {
                ViewBag.oldEntity = v_lxk_11_ml_productlistApp.GetItem(number).ToJson();
            }
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetCarModelJson(Pagination pagination, string keyword)
        {
            var data = new
            {
                rows = plm_cp_vehiclenumberApp.GetList(pagination, keyword, "", "", "", "", ""),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ChooseCarModel(string numbers)
        {
            ViewBag.numbers = (numbers == null) ? "" : numbers;
            return View();
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitProcessRouteCateForm(string status, LXK_11_ML_ProductListEntity entity, string keyValue)
        {
            if (status == "I")
            {
                if (lxk_11_ml_productlistApp.CheckedEntity(entity))
                {
                    lxk_11_ml_productlistApp.ExecInsertContent(entity);
                    return Success("新增操作成功。");
                }
                else
                {
                    return Error("新增失败，已经存在编号为“" + entity.FProductNO + "”的台套目录数据。");
                }
            }
            else if (status == "U")
            {
                lxk_11_ml_productlistApp.ExecUpdateContent(entity);
                return Success("修改操作成功。");
            }
            else if (status == "D")
            {
                LXK_11_ML_ProductListEntity oldEntity = lxk_11_ml_productlistApp.GetForm(keyValue);
                if (oldEntity != null)
                {
                    if (oldEntity.MaintainStatus == "0")
                    {
                        lxk_11_ml_productlistApp.DeleteForm(oldEntity.FProductID);
                    }
                    else if (oldEntity.MaintainStatus == "1")
                    {
                        oldEntity.MaintainStatus = "2";
                        lxk_11_ml_productlistApp.SubmitForm(oldEntity, oldEntity.FProductID);
                    }
                    if (oldEntity.FOrderNum.HasValue)
                    {
                        sys_runparamApp.FastInsert("CXBHQX", oldEntity.FOrderNum.Value.ToString("0"), "新增车型序号取消", "", "Z");
                        lxk_13_lx_productlistinApp.ResetProductSum(oldEntity.FOrderNum.Value.ToString("0"));
                    }
                    return Success("删除操作成功。");
                }
                else
                {
                    return Error("删除失败，没有找到ID“" + keyValue + "”对应的数据。");
                }
            }
            else if (status == "P")
            {
                string ids = "";
                List<string> tmpIds = string.IsNullOrEmpty(keyValue) ? new List<string>() : keyValue.Split(',').ToList();
                foreach (var item in tmpIds)
                {
                    if (!string.IsNullOrEmpty(item))
                    {
                        ids += "'" + item + "',";
                    }
                }
                ids = ids.TrimEnd(',');
                lxk_11_ml_productlistApp.ExecPublish(ids);
                return Success("发布操作成功。");
            }
            else if (status == "W")
            {
                string ids = "";
                List<string> tmpIds = string.IsNullOrEmpty(keyValue) ? new List<string>() : keyValue.Split(',').ToList();
                foreach (var item in tmpIds)
                {
                    if (!string.IsNullOrEmpty(item))
                    {
                        ids += "'" + item + "',";
                    }
                }
                ids = ids.TrimEnd(',');
                lxk_11_ml_productlistApp.ExecCanMaintain(ids);
                return Success("明细维护操作成功。");
            }
            else
            {
                return Error("不可识别的操作类型。");
            }
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult MaterialQuota(string status)
        {
            status = string.IsNullOrEmpty(status) ? "0" : status;
            ViewBag.status = status;
            return View();
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult MaterialQuotaInput(string status, string number)
        {
            ViewBag.status = (status != "U" && status != "D") ? "I" : status;
            ViewBag.number = (number == null) ? "" : number;
            ViewBag.assembleLine = lxk_16_lx_makelineApp.GetList(new Pagination() { rows = 10000000, sidx = "MakeLineNO", sord = "ASC" }, "");
            ViewBag.materialClass1 = clde_zd_fl_cldeerialclassnoApp.GetList("", "LevelSign='1'");
            ViewBag.materialClass2 = clde_zd_fl_cldeerialclassnoApp.GetList("", "LevelSign='2'").ToJson();

            ViewBag.ggdh = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "材料定额更改单", OperatorProvider.Provider.GetCurrent().UserCode, "", "正式");
            if (status == "U" || status == "D")
            {
                ViewBag.oldEntity = v_clde_11_mx_cldeerialquotaApp.GetItem(number).ToJson();
            }
            return View();
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitMaterialQuotaForm(string status, CLDE_11_MX_CLDEerialQuotaEntity entity, CLDE_11_MX_CLDEerialQuotaEntityExt entityExt, string keyValue)
        {
            entity.MaterialSizes = "";
            entity.RoughsSize = "";
            entity.Roughsstandard = "";
            if (entity != null && entityExt != null)
            {
                if (entityExt.MaterialSizes1.HasValue)
                {
                    entity.MaterialSizes += entityExt.MaterialSizes1.Value.ToString("0.00").PadLeft(5, ' ');
                    if (entityExt.MaterialSizes2.HasValue)
                    {
                        entity.MaterialSizes += "x" + entityExt.MaterialSizes2.Value.ToString("0").PadLeft(4, ' ');
                        if (!string.IsNullOrEmpty(entityExt.MaterialSizes3) && entityExt.MaterialSizes3 != "C")
                        {
                            decimal dd = 0;
                            if (decimal.TryParse(entityExt.MaterialSizes3, out dd))
                            {
                                entity.MaterialSizes += "x" + dd.ToString("0").PadLeft(5, ' ');
                            }
                        }
                    }
                }
                
                if (entity.RoughsType == "K" || entity.RoughsType == "T") {
                    if (entityExt.RoughsSize1.HasValue)
                    {
                        entity.RoughsSize += entityExt.RoughsSize1.Value.ToString("0.0").PadLeft(6, ' ');
                        if (entityExt.RoughsSize2.HasValue)
                        {
                            entity.RoughsSize += "x" + entityExt.RoughsSize2.Value.ToString("0.0").PadLeft(6, ' ');
                            if (entityExt.RoughsSize3.HasValue)
                            {
                                entity.RoughsSize += "/" + entityExt.RoughsSize3.Value.ToString("0").PadLeft(2, ' ');
                                if (entityExt.RoughsSize4.HasValue)
                                {
                                    entity.RoughsSize += "+" + entityExt.RoughsSize4.Value.ToString("0.0").PadLeft(5, ' ');
                                }
                            }
                        }
                    }
                }

                if (entityExt.Roughsstandard1.HasValue)
                {
                    entity.Roughsstandard += entityExt.Roughsstandard1.Value.ToString("0.00").PadLeft(7, ' ');
                    if (entityExt.Roughsstandard2.HasValue)
                    {
                        entity.Roughsstandard += "x" + entityExt.Roughsstandard2.Value.ToString("0.00").PadLeft(7, ' ');
                    }
                }
            }

            if (status == "I")
            {
                if (clde_11_mx_cldeerialquotaApp.CheckedEntity(entity))
                {
                    entity.MaintainStatus = "0";
                    CLDE_12_GG_CLDEerialQuota_DAEntity daEntity = new CLDE_12_GG_CLDEerialQuota_DAEntity();
                    EntityClone.Clone<CLDE_11_MX_CLDEerialQuotaEntity, CLDE_12_GG_CLDEerialQuota_DAEntity>(entity, daEntity);
                    daEntity.ChangeType = "C";

                    clde_11_mx_cldeerialquotaApp.SubmitForm(entity, "");
                    clde_12_gg_cldeerialquota_daApp.SubmitForm(daEntity, "");

                    return Success("新增操作成功。");
                }
                else
                {
                    return Error("新增失败，已经存在相同零件编号的数据。");
                }
            }
            else if (status == "U")
            {
                if (clde_11_mx_cldeerialquotaApp.CheckedEntity(entity))
                {
                    CLDE_12_GG_CLDEerialQuota_DAEntity daEntity = new CLDE_12_GG_CLDEerialQuota_DAEntity();
                    EntityClone.Clone<CLDE_11_MX_CLDEerialQuotaEntity, CLDE_12_GG_CLDEerialQuota_DAEntity>(entity, daEntity);
                    daEntity.ChangeType = "C";

                    CLDE_11_MX_CLDEerialQuotaEntity oldEntity = clde_11_mx_cldeerialquotaApp.GetForm(entity.CldeID);

                    CLDE_12_GG_CLDEerialQuota_DAEntity oldDaEntity = new CLDE_12_GG_CLDEerialQuota_DAEntity();
                    EntityClone.Clone<CLDE_11_MX_CLDEerialQuotaEntity, CLDE_12_GG_CLDEerialQuota_DAEntity>(oldEntity, oldDaEntity);
                    
                    oldDaEntity.ChangeType = "Q";
                    oldDaEntity.MateAlterTecNO = daEntity.MateAlterTecNO;
                    clde_12_gg_cldeerialquota_daApp.SubmitForm(oldDaEntity, "");

                    clde_11_mx_cldeerialquotaApp.SubmitForm(entity, entity.CldeID);

                    daEntity.ChangeType = "C";
                    clde_12_gg_cldeerialquota_daApp.SubmitForm(daEntity, "");

                    return Success("修改操作成功。");
                }
                else
                {
                    return Error("修改失败，已经存在相同零件编号的数据。");
                }
            }
            else if (status == "D")
            {
                CLDE_11_MX_CLDEerialQuotaEntity oldEntity = clde_11_mx_cldeerialquotaApp.GetForm(keyValue);

                CLDE_12_GG_CLDEerialQuota_DAEntity oldDaEntity = new CLDE_12_GG_CLDEerialQuota_DAEntity();
                EntityClone.Clone<CLDE_11_MX_CLDEerialQuotaEntity, CLDE_12_GG_CLDEerialQuota_DAEntity>(oldEntity, oldDaEntity);

                oldDaEntity.MateAlterTecNO = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "材料定额更改单", OperatorProvider.Provider.GetCurrent().UserCode, "", "正式");
                oldDaEntity.ChangeType = "Q";
                clde_12_gg_cldeerialquota_daApp.SubmitForm(oldDaEntity, "");

                clde_11_mx_cldeerialquotaApp.DeleteForm(oldEntity.CldeID);

                return Success("删除操作成功。");
            }
            else if (status == "P")
            {
                string ids = "";
                List<string> tmpIds = string.IsNullOrEmpty(keyValue) ? new List<string>() : keyValue.Split(',').ToList();
                foreach (var item in tmpIds)
                {
                    if (!string.IsNullOrEmpty(item))
                    {
                        ids += "'" + item + "',";
                    }
                }
                ids = ids.TrimEnd(',');
                clde_11_mx_cldeerialquotaApp.PublishEntitys(ids);
                return Success("发布操作成功。");
            }
            else
            {
                return Error("不可识别的操作类型。");
            }
        }

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ShearingBlanking()
        {
            return View();
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ShearingBlankingInput()
        {
            return View();
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ShearingBlankingShow()
        {
            return View();
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ChooseMold()
        {
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetMoldListJson(Pagination pagination, string keyword)
        {
            var data = new
            {
                rows = v_mol_11_da_moldApp.GetList(pagination, keyword),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ShearingProcessList(string status)
        {
            status = string.IsNullOrEmpty(status) ? "0" : status;
            ViewBag.status = status;
            return View();
        }        
        
        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetShearingProcessListJson(Pagination pagination, string FProduction, string Process)
        {
            var data = new
            {
                rows = v_gyk_51_jq_tecgxdataApp.GetList(pagination, FProduction, Process),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetShearingProcessDocumentJson(Pagination pagination, string FProduction, string Process)
        {
            var data = new
            {
                rows = v_gyk_53_jq_tecgxdata_daApp.GetList(pagination, FProduction, Process),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ShearingProcess()
        {
            ViewBag.fcontainer = zsj_21_rq_datcontainerApp.GetList();
            ViewBag.assembleLine = lxk_16_lx_makelineApp.GetList(new Pagination() { rows = 10000000, sidx = "MakeLineNO", sord = "ASC" }, "");
            ViewBag.fcontainer = zsj_21_rq_datcontainerApp.GetList();
            ViewBag.equipList = v_bus_sj_dictionaryApp.GetEquipLineList();
            ViewBag.equipModelListJson = equ_11_da_cequipinfoApp.GetEquipModelList().ToJson();
            ViewBag.equipnoListJson = equ_11_da_cequipinfoApp.GetEquipNOList().ToJson();

            return View();
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitShearingProcess(string status, GYK_51_JQ_TecGXDataEntity gxdEntity, GYK_52_JQ_ProductTimeEntity ptEntity, decimal? Manhour_JQ, decimal? Technologyhour_JQ, decimal? Moduelhour_JQ)
        {
            ptEntity.Manhour = Manhour_JQ;
            ptEntity.Technologyhour = Technologyhour_JQ;
            ptEntity.Moduelhour = Moduelhour_JQ;

            GYK_53_JQ_TecGXData_DAEntity daEntity = new GYK_53_JQ_TecGXData_DAEntity();
            if (status == "U") 
            {
                GYK_52_JQ_ProductTimeEntity oldPTEntity = gyk_52_jq_producttimeApp.GetItem(ptEntity.FProductionNO, ptEntity.FProCompanyNO, ptEntity.FWorkshop);
                if (oldPTEntity == null)
                {
                    gyk_52_jq_producttimeApp.SubmitForm(ptEntity, "");
                }
                else
                {
                    ptEntity.ManhourID = oldPTEntity.ManhourID;
                    gyk_52_jq_producttimeApp.SubmitForm(ptEntity, oldPTEntity.ManhourID);
                }


                GYK_51_JQ_TecGXDataEntity oldGXDEntity = gyk_51_jq_tecgxdataApp.GetItem(gxdEntity.FProductionNO, gxdEntity.FProCompanyNO, gxdEntity.FWorkshop, gxdEntity.ProcessNO);
                
                EntityClone.Clone<GYK_51_JQ_TecGXDataEntity, GYK_53_JQ_TecGXData_DAEntity>(gxdEntity, daEntity);

                if (oldGXDEntity == null)
                {
                    gyk_51_jq_tecgxdataApp.SubmitForm(gxdEntity, "");

                    daEntity.ChangeType = "XZ";
                    gyk_53_jq_tecgxdata_daApp.SubmitForm(daEntity, "");
                }
                else
                {
                    gxdEntity.ProcessID = oldGXDEntity.ProcessID;
                    gyk_51_jq_tecgxdataApp.SubmitForm(gxdEntity, oldGXDEntity.ProcessID);

                    daEntity.ChangeType = "XG";
                    gyk_53_jq_tecgxdata_daApp.SubmitForm(daEntity, "");
                }
                return Success("保存操作成功。");
            }
            else if (status == "D")
            {
                GYK_51_JQ_TecGXDataEntity oldGXDEntity = gyk_51_jq_tecgxdataApp.GetItem(gxdEntity.FProductionNO, gxdEntity.FProCompanyNO, gxdEntity.FWorkshop, gxdEntity.ProcessNO);
                if (oldGXDEntity == null)
                {
                    return Error("没有找到待删除的数据，删除失败。");
                }
                else
                {
                    EntityClone.Clone<GYK_51_JQ_TecGXDataEntity, GYK_53_JQ_TecGXData_DAEntity>(oldGXDEntity, daEntity);

                    gyk_51_jq_tecgxdataApp.DeleteForm(oldGXDEntity.ProcessID);

                    daEntity.ChangeType = "SC";
                    gyk_53_jq_tecgxdata_daApp.SubmitForm(daEntity, "");

                    return Success("删除操作成功。");
                }
            }
            else
            {
                return Error("不可识别的操作类型。");
            }
        }

        public ActionResult StampingProcessList(string status)
        {
            status = string.IsNullOrEmpty(status) ? "0" : status;
            ViewBag.status = status;
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetStampingProcessListJson(Pagination pagination, string FProduction, string Process)
        {
            var data = new
            {
                rows = v_gyk_41_cy_tecgxdataApp.GetList(pagination, FProduction, Process),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetStampingProcessDocumentJson(Pagination pagination, string FProduction, string Process)
        {
            var data = new
            {
                rows = v_gyk_43_cy_tecgxdata_daApp.GetList(pagination, FProduction, Process),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult StampingProcess()
        {
            ViewBag.fcontainer = zsj_21_rq_datcontainerApp.GetList();
            ViewBag.assembleLine = lxk_16_lx_makelineApp.GetList(new Pagination() { rows = 10000000, sidx = "MakeLineNO", sord = "ASC" }, "");
            ViewBag.fcontainer = zsj_21_rq_datcontainerApp.GetList();
            ViewBag.equipList = v_bus_sj_dictionaryApp.GetEquipLineList();
            ViewBag.equipModelListJson = equ_11_da_cequipinfoApp.GetEquipModelList().ToJson();
            ViewBag.equipnoListJson = equ_11_da_cequipinfoApp.GetEquipNOList().ToJson();

            return View();
        }
        
        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitStampingProcess(string status, GYK_41_CY_TecGXDataEntity gxdEntity, GYK_42_CY_ProductTimeEntity ptEntity)
        {
            GYK_43_CY_TecGXData_DAEntity daEntity = new GYK_43_CY_TecGXData_DAEntity();
            if (status == "U")
            {
                GYK_42_CY_ProductTimeEntity oldPTEntity = gyk_42_cy_producttimeApp.GetItem(ptEntity.FProductionNO, ptEntity.FProCompanyNO, ptEntity.FWorkshop);
                if (oldPTEntity == null)
                {
                    gyk_42_cy_producttimeApp.SubmitForm(ptEntity, "");
                }
                else
                {
                    ptEntity.ManhourID = oldPTEntity.ManhourID;
                    gyk_42_cy_producttimeApp.SubmitForm(ptEntity, oldPTEntity.ManhourID);
                }

                GYK_41_CY_TecGXDataEntity oldGXDEntity = gyk_41_cy_tecgxdataApp.GetItem(gxdEntity.FProductionNO, gxdEntity.FProCompanyNO, gxdEntity.FWorkshop, gxdEntity.ProcessNO);

                EntityClone.Clone<GYK_41_CY_TecGXDataEntity, GYK_43_CY_TecGXData_DAEntity>(gxdEntity, daEntity);

                if (oldGXDEntity == null)
                {
                    gyk_41_cy_tecgxdataApp.SubmitForm(gxdEntity, "");

                    daEntity.ChangeType = "XZ";
                    gyk_43_cy_tecgxdata_daApp.SubmitForm(daEntity, "");
                }
                else
                {
                    gxdEntity.ProcessID = oldGXDEntity.ProcessID;
                    gyk_41_cy_tecgxdataApp.SubmitForm(gxdEntity, oldGXDEntity.ProcessID);

                    daEntity.ChangeType = "XG";
                    gyk_43_cy_tecgxdata_daApp.SubmitForm(daEntity, "");
                }
                return Success("保存操作成功。");
            }
            else if (status == "D")
            {
                GYK_41_CY_TecGXDataEntity oldGXDEntity = gyk_41_cy_tecgxdataApp.GetItem(gxdEntity.FProductionNO, gxdEntity.FProCompanyNO, gxdEntity.FWorkshop, gxdEntity.ProcessNO);
                if (oldGXDEntity == null)
                {
                    return Error("没有找到待删除的数据，删除失败。");
                }
                else
                {
                    EntityClone.Clone<GYK_41_CY_TecGXDataEntity, GYK_43_CY_TecGXData_DAEntity>(oldGXDEntity, daEntity);

                    gyk_41_cy_tecgxdataApp.DeleteForm(oldGXDEntity.ProcessID);

                    daEntity.ChangeType = "SC";
                    gyk_43_cy_tecgxdata_daApp.SubmitForm(daEntity, "");

                    return Success("删除操作成功。");
                }
            }
            else
            {
                return Error("不可识别的操作类型。");
            }
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult PackingList(string status)
        {
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetPackingListJson(Pagination pagination, string keyword)
        {
            var data = new
            {
                rows = v_gyk_61_wl_datstortransApp.GetList(pagination, keyword),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetPackingSortJson(string sidx, string sord, int rows, string keyword, string currNumber)
        {
            Pagination pagination = new Pagination();
            pagination.rows = int.MaxValue;
            pagination.page = 1;
            pagination.sidx = sidx;
            pagination.sord = sord;
            var list = v_gyk_61_wl_datstortransApp.GetList(pagination, keyword);
            int index = 0;
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].FStorTransID == currNumber)
                {
                    index = i + 1;
                    break;
                }
            }
            if (index > 0)
            {
                var data = new
                {
                    currIndex = index % rows,
                    currPage = (index % rows == 0) ? (index / rows) : (index / rows) + 1
                };
                return Content(data.ToJson());
            }
            else
            {
                var data = new
                {
                    currIndex = 1,
                    currPage = 1
                };
                return Content(data.ToJson());
            }
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult PackingListInput(string status, string number)
        {
            ViewBag.status = (status != "U" && status != "D") ? "I" : status;
            ViewBag.number = (number == null) ? "" : number;
            ViewBag.fproductionType = v_bus_sj_dictionaryApp.GetListByClassNo("01");
            ViewBag.fcontainer = zsj_21_rq_datcontainerApp.GetList();
            ViewBag.pallet = zsj_22_tp_palletApp.GetList();
            if (status == "U" || status == "D")
            {
                ViewBag.oldEntity = v_gyk_61_wl_datstortransApp.GetItem(number).ToJson();
            }
            return View();
        }

        class CompanysClass
        {
            public string UnitNO { get; set; }
            public string UnitShortName { get; set; }
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ChooseSupplier(string numbers, string names)
        {
            List<string> numberList = numbers.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
            List<string> nameList = names.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
            List<CompanysClass> companysList = new List<CompanysClass>();
            for (int i = 0; i < numberList.Count; i++)
            {
                CompanysClass item = new CompanysClass();
                item.UnitNO = numberList[i];
                item.UnitShortName = (nameList.Count > i) ? nameList[i] : "";
                companysList.Add(item);
            }

            ViewBag.companys = companysList.ToJson();
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetSupplierJson(Pagination pagination, string keyword)
        {
            var data = new
            {
                rows = zsj_b1_gh_supplierinformationApp.GetList(pagination, keyword, "IsProduct ='1' or IsCustomer='1'"),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }



        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitPackingListForm(string status, GYK_61_WL_DatStorTransEntity entity, string keyValue)
        {
            if (status == "I")
            {
                if (gyk_61_wl_datstortransApp.CheckedEntity(entity))
                {
                    gyk_61_wl_datstortransApp.SubmitForm(entity, "");
                    GYK_62_WL_DatStorTrans_DAEntity daEntity = new GYK_62_WL_DatStorTrans_DAEntity();
                    EntityClone.Clone<GYK_61_WL_DatStorTransEntity, GYK_62_WL_DatStorTrans_DAEntity>(entity, daEntity);
                    daEntity.ChangeType = "C";
                    gyk_62_wl_datstortrans_daApp.SubmitForm(daEntity, "");

                    return Success("新增操作成功。", entity.FStorTransID);
                }
                else
                {
                    return Error("新增失败，已经存在相同零件和容器数据。");
                }
            }
            else if (status == "U")
            {
                if (gyk_61_wl_datstortransApp.CheckedEntity(entity))
                {
                    GYK_61_WL_DatStorTransEntity oldEntity = gyk_61_wl_datstortransApp.GetForm(entity.FStorTransID);
                    GYK_62_WL_DatStorTrans_DAEntity oldDaEntity = new GYK_62_WL_DatStorTrans_DAEntity();
                    EntityClone.Clone<GYK_61_WL_DatStorTransEntity, GYK_62_WL_DatStorTrans_DAEntity>(oldEntity, oldDaEntity);
                    oldDaEntity.ChangeType = "Q";
                    gyk_62_wl_datstortrans_daApp.SubmitForm(oldDaEntity, "");

                    gyk_61_wl_datstortransApp.SubmitForm(entity, entity.FStorTransID);

                    GYK_62_WL_DatStorTrans_DAEntity daEntity = new GYK_62_WL_DatStorTrans_DAEntity();
                    EntityClone.Clone<GYK_61_WL_DatStorTransEntity, GYK_62_WL_DatStorTrans_DAEntity>(entity, daEntity);
                    daEntity.ChangeType = "C";
                    gyk_62_wl_datstortrans_daApp.SubmitForm(daEntity, "");

                    return Success("修改操作成功。");
                }
                else
                {
                    return Error("修改失败，已经存在相同零件和容器数据。");
                }
            }
            else if (status == "D")
            {
                GYK_61_WL_DatStorTransEntity oldEntity = gyk_61_wl_datstortransApp.GetForm(keyValue);
                GYK_62_WL_DatStorTrans_DAEntity oldDaEntity = new GYK_62_WL_DatStorTrans_DAEntity();
                EntityClone.Clone<GYK_61_WL_DatStorTransEntity, GYK_62_WL_DatStorTrans_DAEntity>(oldEntity, oldDaEntity);
                oldDaEntity.ChangeType = "Q";
                gyk_62_wl_datstortrans_daApp.SubmitForm(oldDaEntity, "");

                gyk_61_wl_datstortransApp.DeleteForm(keyValue);

                return Success("删除操作成功。");
            }
            else
            {
                return Error("不可识别的操作类型。");
            }
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult StampingKit()
        {
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetStampingKitJson(Pagination pagination, string keyword)
        {
            var data = new
            {
                rows = v_clde_31_tc_cldeerialcombineApp.GetList(pagination, keyword),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult StampingKitInput(string status, string number)
        {
            ViewBag.status = (status != "U" && status != "D") ? "I" : status;
            ViewBag.number = (number == null) ? "" : number;
            if (status == "U" || status == "D")
            {
                ViewBag.oldEntity = v_clde_31_tc_cldeerialcombineApp.GetItem(number).ToJson();
            }
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetProductNoCombineJson(Pagination pagination, string keyword, string combineNo, string extIds)
        {
            var data = new
            {
                rows = zsj_11_lj_productionApp.GetList(pagination, keyword, combineNo, extIds),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetCombineProductJson(Pagination pagination, string combineNo)
        {
            var data = new
            {
                rows = v_clde_31_tc_cldeerialcombineApp.GetListByNo(pagination, combineNo),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitStampingKitInputForm(string status, string listContent, string CombineID, string CombineNO, string CombineName)
        {
           List<CLDE_31_TC_CLDEerialCombineEntity> list = listContent.ToObject<List<CLDE_31_TC_CLDEerialCombineEntity>>();
            if (status == "I")
            {
                if (zsj_11_lj_productionApp.CheckedByNo(CombineNO))
                {
                    ZSJ_11_LJ_ProductionEntity entity = new ZSJ_11_LJ_ProductionEntity();
                    entity.FProductionNO = CombineNO;
                    entity.FProductionName = CombineName;
                    zsj_11_lj_productionApp.SubmitForm(entity, "");

                    clde_31_tc_cldeerialcombineApp.DeleteFormByNumber(CombineNO);
                    clde_31_tc_cldeerialcombineApp.InsertForm(list);
                    return Success("新增操作成功。");
                }
                else
                {
                    return Error("新增失败，已经存在相同的合件编号。");
                }
            }
            else if (status == "U")
            {
                ZSJ_11_LJ_ProductionEntity entity = zsj_11_lj_productionApp.GetItem(CombineNO);
                if (entity != null)
                { 
                    entity.FProductionName = CombineName;
                    zsj_11_lj_productionApp.SubmitForm(entity, entity.FProductionID);                
                }

                clde_31_tc_cldeerialcombineApp.DeleteFormByNumber(CombineNO);
                clde_31_tc_cldeerialcombineApp.InsertForm(list);

                return Success("修改操作成功。");
            }
            else if (status == "D")
            {
                zsj_11_lj_productionApp.DeleteFormByNumber(CombineNO);
                clde_31_tc_cldeerialcombineApp.DeleteFormByNumber(CombineNO);

                return Success("删除操作成功。");
            }
            else
            {
                return Error("不可识别的操作类型。");
            }
        }

        public ActionResult ResidueList()
        {
            return View();
        }
        
        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetResidueListJson(Pagination pagination, string FProduction, string MaterialCode, string MaterialThick)
        {
            var data = new
            {
                rows = v_clde_41_yl_blcornerApp.GetList(pagination, FProduction, MaterialCode, MaterialThick),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ResidueListInput(string status, string number)
        {
            ViewBag.status = (status != "U" && status != "D") ? "I" : status;
            ViewBag.number = (number == null) ? "" : number;
            if (status == "U" || status == "D")
            {
                ViewBag.oldEntity = v_clde_41_yl_blcornerApp.GetForm(number).ToJson();
            }
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetResidueSortJson(string sidx, string sord, int rows, string FProduction, string MaterialCode, string MaterialThick, string currNumber)
        {
            Pagination pagination = new Pagination();
            pagination.rows = int.MaxValue;
            pagination.page = 1;
            pagination.sidx = sidx;
            pagination.sord = sord;
            var list = v_clde_41_yl_blcornerApp.GetList(pagination, FProduction, MaterialCode, MaterialThick);
            int index = 0;
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].MaterialID == currNumber)
                {
                    index = i + 1;
                    break;
                }
            }
            if (index > 0)
            {
                var data = new
                {
                    currIndex = index % rows,
                    currPage = (index % rows == 0) ? (index / rows) : (index / rows) + 1
                };
                return Content(data.ToJson());
            }
            else
            {
                var data = new
                {
                    currIndex = 1,
                    currPage = 1
                };
                return Content(data.ToJson());
            }
        }


        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitResidueListForm(string status, CLDE_41_YL_BLCornerEntity entity, string keyValue)
        {
            if (status == "I")
            {
                if (clde_41_yl_blcornerApp.CheckedEntity(entity))
                {
                    clde_41_yl_blcornerApp.SubmitForm(entity, "");
                    return Success("新增操作成功。", entity.MaterialID);
                }
                else
                {
                    return Error("新增失败，已经存在相同零件和材料数据。");
                }
            }
            else if (status == "U")
            {
                if (clde_41_yl_blcornerApp.CheckedEntity(entity))
                {
                    CLDE_41_YL_BLCornerEntity oldEntity = clde_41_yl_blcornerApp.GetForm(entity.MaterialID);
                    if (oldEntity != null)
                    {
                        clde_41_yl_blcornerApp.SubmitForm(entity, entity.MaterialID);
                        return Success("修改操作成功。", entity.MaterialID);  
                    }
                    else 
                    {
                        return Error("修改失败，未找到待修改的数据。");               
                    }
                }
                else
                {
                    return Error("修改失败，已经存在相同零件和材料数据。");
                }
            }
            else if (status == "D")
            {
                CLDE_41_YL_BLCornerEntity oldEntity = clde_41_yl_blcornerApp.GetForm(keyValue);
                if (oldEntity != null)
                {
                    clde_41_yl_blcornerApp.DeleteForm(keyValue);
                    return Success("删除操作成功。");
                }
                else
                {
                    return Error("删除失败，未找到待删除的数据。");
                }
            }
            else
            {
                return Error("不可识别的操作类型。");
            }
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult UnitStamping()
        {
            ViewBag.assembleLine = lxk_16_lx_makelineApp.GetList(new Pagination() { rows = 10000000, sidx = "MakeLineNO", sord = "ASC" }, "");
            ViewBag.productList = lxk_11_ml_productlistApp.GetList();
            ViewBag.productType = v_bus_sj_dictionaryApp.GetListByClassNo("04");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetUnitStampingJson(Pagination pagination, string AssembleLine, string FOrderNum, string FProduction, string ProductType, string MakeLine)
        {
            var data = new
            {
                rows = v_lxk_13_lx_productlistinApp.GetListByNum(pagination, AssembleLine, FOrderNum, FProduction, ProductType, MakeLine),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult StampingClass()
        {
            ViewBag.assembleLine = lxk_16_lx_makelineApp.GetList(new Pagination() { rows = 10000000, sidx = "MakeLineNO", sord = "ASC" }, "");
            ViewBag.productList = lxk_11_ml_productlistApp.GetList();
            ViewBag.productType = v_bus_sj_dictionaryApp.GetListByClassNo("04");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetStampingClassJson(Pagination pagination, string AssembleLine, string FOrderNum, string FProduction, string ProductType, string MakeLine)
        {
            var data = new
            {
                rows = v_lxk_13_lx_productlistinApp.GetListByNum(pagination, AssembleLine, FOrderNum, FProduction, ProductType, MakeLine),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ProductionNumber()
        {
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetProductionNumberJson(Pagination pagination, string CNFProductionNO, string CNFProductionName, string CNReferenceName)
        {
            var data = new
            {
                rows = v_zsj_11_lj_productionApp.GetList(pagination, CNFProductionNO, CNFProductionName, CNReferenceName),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitStampingClassForm(ZSJ_11_LJ_ProductionEntity entity)
        {
            if (entity != null && !string.IsNullOrEmpty(entity.FProductionID))
            {
                zsj_11_lj_productionApp.SubmitForm(entity, entity.FProductionID);
                return Success("数据保存操作成功。");
            }
            else
            {
                return Error("数据不全，无法操作。");
            }
        }
    }
}
